<template>
  <div class="header">
    <router-link tag="div" class="header-abs" to="/"  v-show="showabs">
      <span class="iconfont header-abs-back">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="!showabs" :style="opacityStyle">
      <router-link to="/">
        <div class="header-back">
          <span class="iconfont">&#xe624;</span>
        </div>
      </router-link>
      <div>
        景点详情
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showabs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    getScrollTop () {
      var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
      if (scrollTop > 60) {
        this.showabs = false
        let opacity = scrollTop / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
      } else {
        this.showabs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.getScrollTop)
  },
  deactivated () {
    window.removeEventListener('scroll', this.getScrollTop)
  }
}
</script>

<style lang="stylus" scoped="">
  @import '~styles/varibles.styl'
  .header-abs
    width: 0.8rem
    height: 0.8rem
    border-radius: 0.4rem
    background: rgb(0, 0, 0, 0.8)
    position: absolute
    top: 0.2rem
    left: 0.2rem
    text-align: center
    .header-abs-back
      color: #fff
      line-height: 0.8rem
  .header-fixed
    z-index: 3
    position: fixed
    top: 0
    left: 0
    right: 0
    height: 0.86rem
    line-height: 0.86rem
    text-align: center
    background: $bgColor
    font-size: 0.32rem
    color: #fff
    .header-back
      position: absolute
      top: 0
      left: 0
      float: left
      width: 0.64rem
      text-align: center
      color: #fff
</style>
